/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.notaria.guerrasalas.be;

import com.notaria.guerrasalas.util.UtilGS;
import java.io.Serializable;
import javax.persistence.Basic;
import javax.persistence.Column;
import javax.persistence.DiscriminatorValue;
import javax.persistence.Entity;
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;
import javax.persistence.PrimaryKeyJoinColumn;
import javax.persistence.Table;

/**
 *
 * @author Administrador
 */
@Entity
@Table(name = "BOLETA_VENTA")
@NamedQueries({
    @NamedQuery(name = "BoletaVenta.findAll", query = "SELECT b FROM BoletaVenta b"),
    @NamedQuery(name = "BoletaVenta.findByIdBoleta", query = "SELECT b FROM BoletaVenta b WHERE b.idDocumentoVenta = :idBoleta"),
    @NamedQuery(name = "BoletaVenta.findByNumero", query = "SELECT b FROM BoletaVenta b WHERE b.numero = :numero"),
    @NamedQuery(name = "BoletaVenta.findByCliente", query = "SELECT b FROM BoletaVenta b WHERE UPPER(b.cliente.nombres) Like :nombres or UPPER(b.cliente.apellidoPaterno) Like :apPaterno or UPPER(b.cliente.apellidoMaterno) Like :apMaterno"),
    @NamedQuery(name = "BoletaVenta.findBetweenDates", query = "SELECT b FROM BoletaVenta b WHERE b.fechaCreacion BETWEEN :fechaInicio AND :fechaFin ORDER BY b.idDocumentoVenta DESC")
})
@PrimaryKeyJoinColumn(name = "ID_BOLETA_VENTA", referencedColumnName = "ID_DOCUMENTO_VENTA")
@DiscriminatorValue(value = "BV")
public class BoletaVenta
        extends DocumentoVenta
        implements Serializable {

    @Basic(optional = false)
    @Column(name = "NUMERO", nullable = false, length = 10)
    private String numero;

    public BoletaVenta() {
    }

    public BoletaVenta(Long idDocumentoVenta) {
        super(idDocumentoVenta);
    }

    public String getNumero() {
        return numero;
    }

    public void setNumero(String numero) {
        this.numero = numero;
    }

    public String getNroBoletaConFormato(){
        return UtilGS.agregarCerosIzquierda(getNumero(), 7);
    }

    @Override
    public boolean equals(Object obj) {
        if (obj == null) {
            return false;
        }
        if (getClass() != obj.getClass()) {
            return false;
        }
        final DocumentoVenta other = (DocumentoVenta) obj;
        if (this.idDocumentoVenta != other.idDocumentoVenta && (this.idDocumentoVenta == null || !this.idDocumentoVenta.equals(other.idDocumentoVenta))) {
            return false;
        }
        return true;
    }

    @Override
    public int hashCode() {
        int hash = 5;
        hash = 19 * hash + (this.idDocumentoVenta != null ? this.idDocumentoVenta.hashCode() : 0);
        return hash;
    }

    @Override
    public String toString() {
        return idDocumentoVenta.toString();
    }
}
